package com.example.lcode.greedy;

public class Question621 {

    public int leastInterval(char[] tasks, int n) {

        int[] counts = new int[26];

        for (char c : tasks) {
            counts[c - 'A'] += 1;
        }

        int max = 0;
        for (int count : counts) {
            max = Math.max(max, count);
        }

        int maxCount = 0;
        for (int count : counts) {
            if (count == max) {
                maxCount++;
            }
        }

        return Math.max((n + 1) * (max - 1) + maxCount, tasks.length);
    }


    public static void main(String[] args) {

    }

}
